package sein.android.hopenote;

import java.nio.channels.GatheringByteChannel;
import java.util.ArrayList;
import java.util.Collection;

import sein.android.hopenote.Const.HopeNoteDb;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.provider.ContactsContract.RawContacts.Data;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class User_List extends ListActivity{
	private DBAdapter HopeNoteDB;
	private SQLiteDatabase db;
	
	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.user_list);
		ArrayList<String> data = new ArrayList<String>(); 

		//데이터베이스 열기
		HopeNoteDB = new DBAdapter(getApplicationContext());
		db = HopeNoteDB.getReadableDatabase();
		
		
		//반환할 컬럼 항목
		String[] getColumns = {HopeNoteDb.COL_USER, HopeNoteDb.COL_SEX, HopeNoteDb.COL_AGE};
		//데이터베이스 쿼리
		Cursor Result = db.query(HopeNoteDb.TB_USER,getColumns, null, null, null, null, null);
		Result.moveToFirst();
		
		while(!Result.isAfterLast()){
			
			String user = Result.getString(0);
			String sex = Result.getString(1);
			String age = Result.getString(2);
			data.add(user+sex+age);
			Result.moveToNext();
			Toast.makeText(this,user+sex+age ,Toast.LENGTH_SHORT).show();
		}
		Result.close();
		
		
		setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,data));
		//setListAdapter(new SimpleCursorAdapter(this, R.layout.row,Result,FROM,TO));
		data.get(getSelectedItemPosition());
		//Result.getPosition();
		
		
	}
	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		// TODO Auto-generated method stub
		super.onListItemClick(l, v, position, id);
		setTitle(position);
		
	}
	
	
}
